package com.imooc.ioc.demo1.Control;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginInterceptor implements HandlerInterceptor {

    // 对用户表单的html 页面进行登陆拦截
    public boolean preHandle(HttpServletRequest request , HttpServletResponse response , Object obj) throws IOException {
        Object sessionObj  =  request.getSession().getAttribute("user");

        if(sessionObj != null){
            return true;
        }

        // 重定向到登录页
        response.sendRedirect("../index.html");

        return false ;
    }

}
